package com.cloudm.technician.ui.modules.cloudm_box.plate_number

import android.os.Bundle
import android.view.MenuItem
import com.cloudm.technician.R
import com.cloudm.technician.extensions.addFragmentToActivity
import com.cloudm.technician.ui.base.BaseActivity

/**
 * 作者: wesley
 * 时间: 2017/12/27
 * 描述: 车牌号界面
 */
class PlateNumberActivity : BaseActivity() {

    private var license: String? = null
    private var fragment: PlateNumberFragment? = null


    override val optionsMenuEnabled: Boolean
        get() = true

    override val menuRes: Int
        get() = R.menu.menu_plate_number

    override fun handleBundle(bundle: Bundle) {
        license = bundle.getString("license")
    }

    override fun initVariables() {

    }

    override fun initViews(savedInstanceState: Bundle?) {
        headerTitle = R.string.scan_result
        displayHomeAsUpEnabled = true

        fragment = manager.findFragmentById(
                R.id.common_content) as? PlateNumberFragment ?: PlateNumberFragment.newInstance(
                license)
        addFragmentToActivity(manager, fragment)
    }

    override fun initListener() {

    }


    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        return when (item?.itemId) {
            R.id.menu_plate_refresh -> {
                fragment?.refresh()
                true
            }

            else -> false
        }
    }
}